// myself/pages/my-training/list/list.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    CDNPATH:app.globalData.CDNPATH,
    params: {
      activityStatus: "",
      currentPage: 1,
      pageSize: 10,
    },
    types: [
      {
        name: '全部',
        value: ''
      },
      {
        name: '未开始',
        value: 'notStart'
      },
      {
        name: '进行中',
        value: 'inProgress'
      },
      {
        name: '已结束',
        value: 'finished'
      }
    ],
    list: [],
    total: 0,
    loading: true,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getList()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  getListByType (e) {
    console.log(e.currentTarget.dataset)
    const { value: activityStatus } = e.currentTarget.dataset.item
    this.setData({
      params: {
        activityStatus,
        pageSize: 10,
        currentPage: 1
      }
    })
    this.getList()
  },
  getList () {
    const { params } = this.data
    const { currentPage } = params
    app.api.post({
      url: 'coaching_vx_student_session_list_my',
      data: params
    }).then(res => {
      let { list } = this.data
      currentPage === 1 ? (list = res.list) : list.push(...res.list)
      this.setData({ list, total: res.total, loading: false })
    })
  },
  loadMore () {
    const { total, list, params } = this.data
    const { currentPage } = params
    if (total > list.length) {
      this.setData({
        'params.currentPage': currentPage + 1
      })
      this.getList()
    }
  },
  checkDetail (e) {
    const { item } = e.currentTarget.dataset
    wx.navigateTo({
      url: `/myself/pages/my-training/detail/detail?coachingSessionId=${item.coachingSessionId}&sensors_ext=05-02`
    })
  }
})